{extend name="admin/b2c/base" /} {block name="resources"/}
<script src="ADMIN_JS/art_dialog.source.js"></script>
<script src="ADMIN_JS/iframe_tools.source.js"></script>
<script src="ADMIN_JS/material_managedialog.js"></script>
<script src="__STATIC__/js/ajax_file_upload.js" type="text/javascript"></script>
<script src="__STATIC__/js/file_upload.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="ADMIN_CSS/defau.css">
<style type="text/css">
.set-style {
	width: 100%;
}

.set-style dl {
	width: 100%;
	font-size: 0;
	/* line-height: 20px; */
	clear: both;
	padding: 0;
	margin: 0;
	border-bottom: dotted 1px #E6E6E6;
	overflow: hidden;
}

.set-style dl dt {
	font-size: 12px;
	line-height: 32px;
	vertical-align: top;
	letter-spacing: normal;
	word-spacing: normal;
	text-align: right;
	display: inline-block;
	width: 19%;
	padding: 10px 1% 10px 0;
	margin: 0;
	font-weight: normal;
}

.set-style dl dd {
	font-size: 12px;
	line-height: 32px;
	vertical-align: top;
	letter-spacing: normal;
	word-spacing: normal;
	display: inline-block;
	width: 78%;
	padding: 10px 0 10px 0;
}

.set-style dl dd input[type="text"] {
	font: 12px/20px Arial;
	color: #777;
	background-color: #FFF;
	vertical-align: top;
	display: inline-block;
	height: 24px;
	line-height: 24px;
	padding: 4px;
	border: 1px solid #CCC;
	outline: 0 none;
	width: 400px;
	margin: 0;
}

.set-style dl dd textarea {
	font: 12px/20px Arial;
	color: #777;
	background-color: #FFF;
	vertical-align: top;
	display: inline-block;
	height: 60px;
	padding: 4px;
	border: solid 1px #CCC;
	outline: 0 none;
	width: 400px;
	margin: 0;
}

.hint {
	font-size: 12px;
	line-height: 16px;
	color: #BBB;
	margin-top: 10px;
}

.set-style dl dd p img {
	border: medium none;
	vertical-align: middle;
}

.class-logo {
	background-color: #FFF;
	position: relative;
	z-index: 1;
}

.class-logo p {
	width: 200px;
	height: 60px;
	line-height: 0;
	background-color: #FFF;
	text-align: center;
	vertical-align: middle;
	display: table-cell;
	*display: block;
	overflow: hidden;
	margin: 0 0 10px;
	border: dashed 1px #E6E6E6;
}

.class-logo p img {
	max-width: 200px;
	max-height: 60px;
	border: medium none;
	vertical-align: middle;
	margin-top: expression(60-this .height/ 2);
	*margin-top: expression(30-this .height/ 2);
}

.edit_button {
	padding-top: 10px;
	padding-bottom: 10px;
	padding-left: 30px;
	padding-right: 30px;
	background-color: #51A351;
	color: #FFF;
	margin: 20px auto;
	border: none;
	display: block;
}

.set-style dl dd p {
	margin-bottom: 0;
}

.error {
	padding-left: 5px !important;
}
</style>
{/block} {block name="main"}
<div class="set-style">
	<input type="hidden" value="{$brand_info.brand_id}" id="brand_id" />
	<dl>
		<dt>品牌名称:</dt>
		<dd>
			<input name="" id="brand_name" type="text"
				value="{$brand_info.brand_name}" /><span class="error">请输入品牌名称</span>
		</dd>
	</dl>
	<dl>
		<dt>品牌首字母:</dt>
		<dd>
			<input name="" id="brand_initial" type="text"
				value="{$brand_info.brand_initial}" /><span class="error">请输入品牌首字母</span>
		</dd>
	</dl>
	<dl>
		<dt>是否推荐</dt>
		<dd>
				<input id="brand_recommend" type="checkbox" class="checkbox" {if
					condition="$brand_info.brand_recommend == 1" }checked="checked" {/if} />
		</dd>
	</dl>
	<dl>
		<dt>商品分类</dt>
		<dd>
			<div class="col-sm-2 category_name">
				<span>{$brand_info['category_name']}</span> <a
					href="javascript:void(0);" onclick="show_select()"
					class="btn btn-default">编辑</a>
			</div>
			<select id="category_id_1" name="account" class="form-control m-b"
				onchange="changeCategory(1)" style="display: none;">
				<option value="0">请选择...</option> {foreach
				name="goods_category_list" item="v1"}
				<option value="{$v1['category_id']}">{$v1['category_name']}</option>
				{/foreach}
			</select> <select id="category_id_2" name="account" class="form-control m-b"
				onchange="changeCategory(2)" style="display: none;">
				<option value="-1">请选择...</option>
			</select> <select id="category_id_3" name="account" class="form-control m-b"
				style="display: none;">
				<option value="-1">请选择...</option>
			</select> <span class="error">请选择商品分类</span>
		</dd>
	</dl>

	<dl>
		<dt>图片:</dt>
		<dd>
			<div class="class-logo">
				<p>
					<img id="imgbrand_pic" src="__UPLOAD__/{$brand_info['brand_pic']}">
				</p>
			</div>
			<a href="javascript:void(0);"
				style="display: block; position: relative; z-index: 1;"> <span
				style="width: 97px; height: 34px; position: absolute; left: 0; top: 0; z-index: 2; cursor: pointer;">
					<input hidefocus="true" size="1" class="input-file"
					name="file_upload" id="uploadImg1" nc_type="change_store_label"
					type="file"
					style="width: 97px; height: 34px; padding: 0; margin: 0; border: none 0; opacity: 0; filter: alpha(opacity = 0); cursor: pointer;"
					onchange="imgUpload(this,'brand_pic');"> <input
					type="hidden" id="brand_pic" value="{$brand_info.brand_pic}" />
			</span> <a class="btn btn-default"> <i class="fa fa-cloud-upload text"></i>
					<span class="text">上传图片</span>
			</a>
				<p class="hint">
					此处理品牌;<br> <span style="color: orange;">建议使用宽200像素-高60像素内的GIF或PNG透明图片；点击下方"提交"按钮后生效。</span>
				</p> <span class="error">请上传图片</span>
		</dd>
	</dl>
	<dl>
		<dt>品牌推荐广告图</dt>
		<dd>
			<div class="class-logo">
				<p>
					<img id="imgbrand_ads" class="imglogo"
						src="__UPLOAD__/{$brand_info.brand_ads}" />
				</p>
			</div>
			<a href="javascript:void(0);"
				style="display: block; position: relative; z-index: 1;"> <span
				style="width: 97px; height: 34px; position: absolute; left: 0; top: 0; z-index: 2; cursor: pointer;">
					<input hidefocus="true" size="1" class="input-file"
					name="file_upload" id="uploadImg2" nc_type="change_store_label"
					type="file"
					style="width: 97px; height: 34px; padding: 0; margin: 0; border: none 0; opacity: 0; filter: alpha(opacity = 0); cursor: pointer;"
					onchange="imgUpload(this,'brand_ads');"> <input
					type="hidden" id="brand_ads" value="{$brand_info.brand_ads}" />
			</span> <a class="btn btn-default"> <i class="fa fa-cloud-upload text"></i>
					<span class="text">上传图片</span>
			</a>
			</a> <span class="error">请上传品牌推荐广告图</span>
		</dd>
	</dl>
	<button class="edit_button" onclick="editGoodsBrand();">提交</button>
</div>
{include file="admin/b2c/openDialog" /}
<script>
	function validation() {
		var brand_name = $("#brand_name");
		var brand_initial = $("#brand_initial");
		var category_id_1 = $("#category_id_1");
		var brand_pic = $("#brand_pic");
		var brand_ads = $("#brand_ads");
		if (brand_name.val() == "") {
			brand_name.next("span").show();
			brand_name.focus();
			return false;
		} else {
			brand_name.next("span").hide();
		}

		if (brand_initial.val() == "") {
			brand_initial.next("span").text("请输入品牌首字母")
			brand_initial.next("span").show();
			brand_initial.focus();
			return false;
		} else if (brand_initial.val().length != 1) {
			brand_initial.next("span").text("品牌首字母必须是单个字母，")
			brand_initial.next("span").show();
			brand_initial.focus();
			return false;
		} else {
			brand_initial.next("span").hide();
		}

		if (category_id_1.val() == 0 ) {
			category_id_1.val("{$brand_info['category_id_1']}");
			if (category_id_1.val() == 0 ) {
				category_id_1.parent().children("span").show();
			}
			return false;
		} else {
			category_id_1.parent().children("span").hide();
		}
		if (brand_pic.val() == "") {
			brand_pic.parent().parent().parent().children("span").show();
			return false;
		} else {
			brand_pic.parent().parent().parent().children("span").hide();
		}

		if (brand_ads.val() == "") {
			brand_ads.parent().parent().parent().children("span").show();
			return false;
		} else {
			brand_ads.parent().parent().parent().children("span").hide();
		}

		return true;
	}
	function editGoodsBrand() {
		if (!validation()) {
			return;
		}
		var brand_id = $("#brand_id").val();
		var brand_name = $("#brand_name").val();
		var brand_initial = $("#brand_initial").val();
		if ($("#brand_recommend").prop("checked")) {
			var brand_recommend = 1;
		} else {
			var brand_recommend = 0;
		}
		var category_id_1 = $("#category_id_1").val();
		var category_id_2 = $("#category_id_2").val();
		var category_id_3 = $("#category_id_3").val();
		var category_name = '';
		if (category_id_3 > 0) {
			category_name = $("#category_id_3 option:selected").text();
		} else if (category_id_2 > 0 && category_id_3 <= 0) {
			category_name = $("#category_id_2 option:selected").text();
		} else if (category_id_1 > 0) {
			category_name = $("#category_id_1 option:selected").text();
		} else {
			category_name = '';
		}
		var brand_pic = $("#brand_pic").val();
		var brand_ads = $("#brand_ads").val();
		$.ajax({
			type : "post",
			url : "ADMIN_MAIN/Goods/updateGoodsBrand",
			data : {
				'brand_id' : brand_id,
				'brand_name' : brand_name,
				'brand_initial' : brand_initial,
				'brand_recommend' : brand_recommend,
				'brand_pic' : brand_pic,
				'brand_ads' : brand_ads,
				'category_id_1' : category_id_1,
				'category_id_2' : category_id_2,
				'category_id_3' : category_id_3,
				'category_name' : category_name
			},
			async : true,
			success : function(data) {
				if (data["code"] > 0) {
					showMessage('success', "商品品牌修改成功",
							'ADMIN_MAIN/Goods/goodsBrandList');
				} else {
					showMessage('error', "商品品牌修改失败");
				}
			}
		});
	}
	/**
	 *图片上传
	 */
	function imgUpload(event, obj) {
		var fileid = $(event).attr("id");
		fileCommonUpload("UPLOAD_URL", fileid, "__UPLOAD__", obj);
	}
	function show_select() {
		$(".category_name").hide();
		$("#category_id_1").show();
	}
	function changeCategory(type) {
		var pid = $("#category_id_" + type).val();
		$.ajax({
			type : "post",
			url : "ADMIN_MAIN/Goods/changeCategory",
			data : {
				'pid' : pid
			},
			success : function(data) {
				if (type == 1) {
					$("#category_id_2 option:gt(0)").remove();
					$("#category_id_3 option:gt(0)").remove();
				} else if (type == 2) {
					$("#category_id_3 option:gt(0)").remove();
				}
				var html = '';
				for (var i = 0; i < data.length; i++) {
					html += '<option value="'+data[i]['category_id']+'">'
							+ data[i]['category_name'] + '</option>';
				}
				if (data.length > 0) {
					$("#category_id_" + (type + 1)).append(html);
					$("#category_id_" + (type + 1)).show();
				}
			}
		});
	}
</script>
{/block}